/*
 ============================================================================
 Name		: FEAppView.cpp
 Author	  : jk
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CFEAppDriverView implementation
 ============================================================================
 */
#include <aknviewappui.h>
#include <avkon.hrh>
#include "FE.hrh"
#include <FE_0xE986B88E.rsg>
#include "FEAppDriverView.h"
#include "FEAppDriverContainer.h"
#include "aknmessagequerydialog.h"
#include <HLPLCH.H> 
#include <aknnotewrappers.h>
#include <FEAppUi.h>
CFEAppDriverView::CFEAppDriverView()
{
	// No implementation required
}

CFEAppDriverView::~CFEAppDriverView()
{
	if (iContainer != NULL)
	{
		AppUi()->RemoveFromViewStack(*this, iContainer);
		delete iContainer;
		iContainer = NULL;
	}
}

CFEAppDriverView* CFEAppDriverView::NewLC()
{
	CFEAppDriverView* self = new (ELeave) CFEAppDriverView();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CFEAppDriverView* CFEAppDriverView::NewL()
{
	CFEAppDriverView* self = CFEAppDriverView::NewLC();
	CleanupStack::Pop(); // self;
	return self;
}

void CFEAppDriverView::ConstructL()
{
	BaseConstructL(R_DRIVER_VIEW);
}

TUid CFEAppDriverView::Id() const
{
	return TUid::Uid(EDriverView);
}

void CFEAppDriverView::HandleCommandL(TInt aCommand)
{
	switch (aCommand)
	{
		case EDriverOpen:
		{
			TUid diskId;
			TBuf8<30> path;
			TInt index = iContainer->GetListBoxCtrl()->CurrentItemIndex();
			iContainer->GetSelectedDriveString(index, path);
			AppUi()->ActivateLocalViewL(TUid::Uid(EDirView), diskId, path);
			break;
		}
		case EDirverHelp:
		{
			CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog();
			dlg->PrepareLC(R_HELP_QUERY_DIALOG);
			HBufC* title = iEikonEnv->AllocReadResourceLC(R_HELP_DIALOG_TITLE);
			dlg->QueryHeading()->SetTextL(*title);
			CleanupStack::PopAndDestroy(); //title
			HBufC* msg = iEikonEnv->AllocReadResourceLC(R_HELP_DIALOG_TEXT);
			dlg->SetMessageTextL(*msg);
			CleanupStack::PopAndDestroy(); //msg
			dlg->RunLD();
			break;
		}
		case EDriverAbout:
		{
			CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog();
			dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
			HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
			dlg->QueryHeading()->SetTextL(*title);
			CleanupStack::PopAndDestroy(); //title
			HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
			dlg->SetMessageTextL(*msg);
			CleanupStack::PopAndDestroy(); //msg
			dlg->RunLD();
			break;
		}
		case EEikCmdExit:
		case EAknSoftkeyExit:
		{
			AppUi()->Exit();
			break;
		}
		default:
			break;
	}
}

void CFEAppDriverView::HandleClientRectChange()
{
	if (iContainer != NULL)
	{
		iContainer->SetRect(ClientRect());
	}
}

void CFEAppDriverView::DoActivateL(const TVwsViewId&, TUid, const TDesC8&)
{
	if (iContainer == NULL)
	{
		iContainer = CFEAppDriverContainer::NewL(ClientRect());
		iContainer->SetMopParent(this);
		AppUi()->AddToStackL(*this, iContainer);

		iContainer->SetView(this);
	}
}

void CFEAppDriverView::DoDeactivate()
{
	if (iContainer != NULL)
	{
		AppUi()->RemoveFromViewStack(*this, iContainer);
		delete iContainer;
		iContainer = NULL;
	}
}

CAknViewAppUi *CFEAppDriverView::GetAppUi()
{
	return AppUi();
}
